home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / x3270 / unix_files / Examples / peer_script.sh < prev   
Encoding:
Linux/UNIX/POSIX Shell Script  |  2008-08-17  |  2.3 KB  |  135 lines

  1. #! /bin/sh
  2. # TSO login script, which runs as a peer of x3270.
  3. # sh version
  4. set -x
  5. me=`echo $0 | sed 's/.*\///'`
  6.  
  7. # Set up login parameters
  8. tcp_host=${1-ibmsys}
  9. dial_user=${2-VTAM}
  10. sna_host=${3-TSO}
  11. userid=${4-USERID}
  12. password=${5-PASSWORD}
  13.  
  14. # Verbose flag for x3270if
  15. #v="-v"
  16.  
  17. # Define some handly local functions.
  18.  
  19. # x3270 interface function
  20. xi()
  21. {
  22.     X3270OUTPUT=6 X3270INPUT=5 x3270if 5>$ip 6<$op $v "$@"
  23. }
  24.  
  25. # Common x3270 Ascii function
  26. ascii()
  27. {
  28.     xi 'Ascii('$1')'
  29. }
  30.  
  31. # Common x3270 String function
  32. string()
  33. {
  34.     xi 'String("'"$@"'")'
  35. }
  36.  
  37. # x3270 cursor column
  38. cursor_col()
  39. {
  40.     xi -s 10
  41. }
  42.  
  43. # x3270 connection status
  44. cstatus()
  45. {
  46.     xi -s 4
  47. }
  48.  
  49. # Failure.
  50. die()
  51. {
  52.     xi "Info(\"$me error: $@\")"
  53.     xi "CloseScript(1)"
  54.     exit 1
  55. }
  56.  
  57. # Set up pipes for x3270 I/O
  58. ip=/tmp/ip.$$
  59. op=/tmp/op.$$
  60. rm -f $ip $op
  61. trap "rm -f $ip $op" 0
  62. trap "exit" 2 3 1 15
  63. mknod $ip p
  64. mknod $op p
  65.  
  66. # Start x3270
  67. x3270 -script -model 2 <$ip >$op &
  68. xp=$!
  69. exec 5>$ip    # hold the pipe open
  70. xi -s 0 >/dev/null || exit 1
  71.  
  72. # Connect to host
  73. xi "Connect($tcp_host)" || die "Connection failed."
  74.  
  75. # Make sure we're connected.
  76. xi Wait
  77. [ "`cstatus`" = N ] && die "Not connected."
  78.  
  79. # Get to a VM command screen
  80. xi Enter
  81.  
  82. # Wait for VM's prompt
  83. while [ "`ascii 1,0,5`" != "Enter" ]
  84. do    sleep 2
  85. done
  86.  
  87. # Dial out to VTAM
  88. string "DIAL $dial_user"
  89. xi Enter
  90. len0=`expr length $dial_user`
  91. sl=`expr 10 + $len0`
  92. dl=`expr 5 + $len0`
  93. while [ "`ascii 0,64,4`" != VTAM ]
  94. do    s="`ascii 8,0,$sl | sed 's/^ *//'`"
  95.     if [ "$s" != "DIALED TO $dial_user" -a "$s" != "" ]
  96.     then    if [ "`ascii 7,0,$dl`" = "DIAL $dial_user" ]
  97.         then    die "Couldn't get to VTAM"
  98.         fi
  99.     fi
  100.     sleep 2
  101. done
  102.  
  103. # Get to the SNA host
  104. string "$sna_host $userid"
  105. xi Enter
  106.  
  107. # Pass VTAM digestion message and initial blank TSO screen
  108. while [ "`ascii 0,21,20`" = "USS COMMAND HAS BEEN" ]
  109. do    sleep 2
  110. done
  111. while :
  112. do    s="`ascii 0,33,11 | sed 's/^ *//'`"
  113.     [ "$s" != "" ] && break
  114.     sleep 2
  115. done
  116.  
  117. # Now verify the "TSO/E LOGON" screen
  118. [ "$s" = "TSO/E LOGON" ] || die "Couldn't get to TSO logon screen"
  119.  
  120. # Pump in the password
  121. string "$password"
  122. xi Enter
  123.  
  124. # Now look for "LOGON IN PROGRESS"
  125. len0=`expr length $userid`
  126. nl=`expr 18 + $len0`
  127. [ "`ascii 0,11,$nl`" = "$userid LOGON IN PROGRESS" ] || die "Couldn't log on"
  128.  
  129. # Make sure TSO is waiting for a '***' enter
  130. [ "`cursor_col`" -eq 5 ] || die "Don't understand logon screen"
  131.  
  132. # Off to ISPF
  133. xi Enter
  134. xi 'CloseScript(0)'
  135.